<?php

$tpldefault=
<<<tpl
<h1 align="center">
	发货单
</h1>
<hr />
<p align="right">
	[发货时间]
</p>
<table class="new-con2 txt-normal" border="1" cellpadding="10" cellspacing="0" width="100%">
	<tbody>
		<tr>
			<td align="left">
				订单号：[订单号]
			</td>
			<td align="left">
				客户名称：[收件人]
			</td>
			<td align="left">
				电话：[收件电话]
			</td>
			<td align="left">
				下单时间：[下单时间]
			</td>
		</tr>
		<tr>
			<td colspan="3" align="left">
				发往地址：[发往地址]
			</td>
			<td align="left">
				邮编：[收件邮编]
			</td>
		</tr>
		<tr>
			<td align="left">
				配送方式：[配送方式]
			</td>
			<td align="left">
				发票信息：[发票信息]
			</td>
			<td align="left">
				发票抬头：[发票抬头]
			</td>
			<td align="left">
				发票内容：[发票内容]
			</td>
		</tr>
		<tr>
			<td align="left">
				产品件数：[产品件数]
			</td>
			<td align="left">
				订单金额：[订单金额]
			</td>
			<td align="left">
				配送费：[配送费]
			</td>
			<td align="left">
				支付方式：[支付方式]
			</td>
		</tr>
		<tr>
			<td colspan="4">
				备注：[备注]
			</td>
		</tr>
		<tr>
			<td colspan="4">
				<div align="center">
					货品列表
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="4">
				<table border="1" cellpadding="10" cellspacing="0" width="100%">
					<tbody>
						<tr>
							<td width="60">
								货品序号
							</td>
							<td width="340">
								货品名称
							</td>
							<td width="100">
								货品单价
							</td>
							<td width="100">
								货品数量
							</td>
							<td width="100">
								小计
							</td>
							<td width="">
								备注
							</td>
						</tr>
						<tr id="[货品]">
							<td>
								[货品序号]
							</td>
							<td>
								[货品名称]
							</td>
							<td>
								[货品单价]
							</td>
							<td>
								[货品数量]
							</td>
							<td>
								[货品小计]
							</td>
							<td>
								[货品备注]
							</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
	</tbody>
</table>
tpl;





if($_POST["act"]=='edit' and is_numeric($_POST['id']))
{
    $id=$_POST['id'];
    $sql="update ".SENDTPL." set title='$_POST[title]',`sendtpl`='$_POST[content]' where id='$id'";
    $db->query($sql);
    $getstr=implode('&',convert($_GET));
    msg("?m=logistics&s=sendtpl.php&$getstr");
}

if($_GET["act"]=='print' )
{
    if(is_numeric($_GET['id'])){
        $id=$_GET['id'];
        $sql="select sendtpl from ".SENDTPL." where id='$id'";
        $db->query($sql);
        $de=$db->fetchRow();
        $sendtpl=$de['sendtpl'];
    }elseif (is_array($_GET['chk'])){
        $id=implode(",",$_GET['chk']);
        $sql="select sendtpl from ".SENDTPL." where id in ($id)";
        $db->query($sql);
        foreach ($de=$db->getRows() as $item){
            $sendtpl.=$item['sendtpl'].'<br/></br/>';
        }
    }
    
    echo '<style>'.'html {margin:0;padding:0;}
body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;padding:5px;}
body, p, div {word-wrap: break-word;}
p {margin:5px 0;}
table {border-collapse:collapse;}
img {border:0;}
noscript {display:none;}input[type="button"]{
    background: url("../image/admin/dialog_button.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
    border: 0 none;
    color: #FFFFFF;
    cursor: pointer;
    font-weight: bold;
    height: 26px;
    margin: 7px 0 3px;
    text-align: center;
    width: 70px;
}'.'</style>';
    echo $sendtpl;
    echo '<br/><br/>';
    echo '<center><input type="button" id="printBtn" value="打印" onclick="printArea();"></center>';
    echo '<script>function printArea(){document.getElementById("printBtn").style.display="none";window.print();if(confirm("打印完成？")){document.getElementById("printBtn").style.display="block";}else{printArea()}}</script>';
    die;
}

if($_POST['act'] and is_array($_POST['chk']))
{
    $id=implode(",",$_POST['chk']);
    if($_POST['act']=='open')
    {
        $db->query("update ".SENDTPL." set status=1 where id in ($id) ");
    }
    if($_POST['act']=='close')
    {
        $db->query("update ".SENDTPL." set status=0,sendtpl='$tpldefault' where id in ($id) ");
    }
    if($_POST['act']=='delete')
    {
        $sql="delete from ".SENDTPL." where id in ($id)";
        $db->query($sql);
    }
    msg("?m=logistics&s=sendtpl.php");
}


if($_GET['editid'] and is_numeric($_GET['editid']))
{
    $sql="select * from ".SENDTPL." where id='$_GET[editid]'";
    $db->query($sql);
    $de=$db->fetchRow();
    $tpl->assign("de",$de);
    
}
else{


	$sql="select * from ".SENDTPL."  order by id";
    $db->query($sql);
    $re=$db->getRows();
	$tpl->assign("re",$re);
}
$tpl->assign("config",$config);
	$tpl->display("sendtpl.htm");
?>